package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-27 21:55
 **/

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /*
    * 上报地理位置
    *   POST  /location
    *   参数： Body  latitude，longitude，addrStr
    * 返回值： 空
     *
    * */
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map){
        String str1 = map.get("latitude").toString();
        Double latitude = Double.valueOf(str1);
        String str2 = map.get("longitude").toString();
        Double longitude = Double.valueOf(str2);
        String addrStr = map.get("addrStr").toString();
        //调用service进行保存
        baiduService.location(latitude,longitude,addrStr);
        return ResponseEntity.ok(null);
    }
}
